Skip to content

Add integration tests #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 10, 2020
Merged

Add integration tests #48

merged 19 commits into from
Mar 10, 2020

Conversation

sfirrin
Copy link
Contributor

@sfirrin sfirrin commented Mar 10, 2020

What does this PR do?

These integration tests do the following:

  1. Build layers using the ./scripts/build_layers.sh script (or don't if $BUILD_LAYERS isn't set)
  2. Deploy sample Lambda handlers for all runtimes using the serverless framework
  3. Invoke each Lambda once for each of the event types defined in ./tests/integration/input_events
  4. Compare the return value of each Lambda invocation for each input event with the snapshot that we have saved for the input event in ./tests/integration/snapshots/return_values
  5. Query for the logs of each Lambda function
  6. Replace invocation-specific data (like timestamps, request IDs) with XXXX to normalize log snapshots
  7. Compare new logs to the snapshot log file that we have saved in ./tests/integration/snapshots/logs
  8. Print any mismatches between snapshots and new logs / return values
  9. Fail the script if a mismatch is found, otherwise succeed

To run integration tests for new changes to the layer:
BUILD_LAYERS=true DD_API_KEY=XXXX aws-vault exec sandbox-account-admin -- ./scripts/run_integration_tests

To regenerate snapshots:
UPDATE_SNAPSHOTS=true DD_API_KEY=XXXX aws-vault exec sandbox-account-admin -- ./scripts/run_integration_tests

This PR also makes a change to the layer itself to hook into the existing request patching so that if env var DD_INTEGRATION_TEST=true, each HTTP request will be logged in this format:
HTTP GET https://ip-ranges.datadoghq.com/ Headers: ["x-datadog-parent-id:XXXX", "x-datadog-sampling-priority:2", "x-datadog-trace-id:XXXX"] Data: {}
so that we can see in the snapshot tests if any HTTP requests have changed.

This is the first step of the integration tests so we are only running them locally for now. In the future we will integrate these tests into our CI.

Testing Guidelines

I've run this many times locally and it is working as expected without being flaky.

Additional Notes

Anything else we should know when reviewing?

@sfirrin sfirrin requested a review from a team as a code owner March 10, 2020 20:32
Copy link
Contributor

@DarcyRaynerDD DarcyRaynerDD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome stuff!

# Return value snapshot file format is snapshots/return_values/{handler}_{runtime}_{input-event}
snapshot_path="./snapshots/return_values/${function_name}_${input_event_name}.json"

return_value=$(serverless invoke -f $function_name --path "./input_events/$input_event_file")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invoke with return value is a neat trick

raw_logs=$(serverless logs -f $function_name --startTime $script_start_time)

# Replace invocation-specific data like timestamps and IDs with XXXX to normalize logs across executions
logs=$(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also pretty cool trick

@sfirrin sfirrin merged commit 613755c into master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants